﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acme.BookStore.Logins;
using Microsoft.AspNetCore.Mvc;
using SC.UserCenter.Infra;
using Volo.Abp.Application.Services;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore.Captchass
{
    [ApiExplorerSettings(GroupName = "v2")]
    public class DeleteCaptcha : ApplicationService, IDeleteCaptcha
    {
        IRepository<Captcha> captchaRepository;

        public DeleteCaptcha(IRepository<Captcha> captchaRepository)
        {
            this.captchaRepository = captchaRepository;
        }
        [HttpDelete]
        public async Task<ApiResult> DeleteCaptchaAsync(string captcha)
        {
            var list = await captchaRepository.FirstOrDefaultAsync(x => x.Code == captcha);
            if (list != null)
            {
                await captchaRepository.HardDeleteAsync(list);
                return ApiResult.Ok();
            }
            else
            {
                return ApiResult.Fail("验证码错误");
            }
        }
    }
}
